package com.inspur.gs.sbssdl.sbwhgl.bpbjgl.bpbjgl.back.bpbjlktz.determinations;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.cef.api.message.*;
import com.inspur.edp.bef.api.action.determination.*;
import com.inspur.edp.bef.spi.action.determination.*;
import com.inspur.edp.cef.entity.changeset.*;
import com.inspur.edp.bef.spi.action.determination.AbstractDetermination;
import com.inspur.edp.bef.api.action.determination.IDeterminationContext;
import com.inspur.edp.cef.entity.condition.EntityFilter;
import com.inspur.edp.cef.entity.condition.FilterCondition;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.bef.api.action.determination.IBeforeRetrieveDtmContext;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.ArrayList;
import java.util.List;

public class bpbjlktzDtmBeforeSave1MgrAction extends AbstractB4SaveDetermination {
	public bpbjlktzDtmBeforeSave1MgrAction(IDeterminationContext context, IChangeDetail change) {
		super(context,change);
	}
	@Override
	public  void execute() {
		String wlbh = (String) getContext().getCurrentData().getValue("wlbh");
		String wlmc = (String) getContext().getCurrentData().getValue("wlmc");

		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			String bpbjtzid = "3f443799-4bc1-409f-a28d-f04742273899";
			IStandardLcp bpbjtzlcp = iLcpFactory.createLcpByBEId(bpbjtzid);

			EntityFilter filter = new EntityFilter();
			ArrayList<FilterCondition> filterConditions = (ArrayList<FilterCondition>) FilterCondition.builder()
					.orEqual("wlbh", wlbh)
					.andEqual("wlmc", wlmc)
					.build();
			filter.addFilterConditions(filterConditions);
			List<IEntityData> query = bpbjtzlcp.query(filter);
			if (!query.isEmpty()){
				throw new RuntimeException("该类的备品备件台账中已存在！");
			}


		} finally {
			SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
		}

	}
	private IEntityData getData() {
		return (IEntityData)super.getContext().getCurrentData();
	}
}



